--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_par_expedzone AS (SELECT * FROM &erp.par_expedzone WHERE 1=2);




DELETE FROM se_par_expedzone;

 INSERT INTO se_par_expedzone
 (SELECT id expedzone_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle expedzone_lib,
         NULL expedzone_lib2,
         NULL eloignement_num

    FROM UV_CZONEXPED) ;

 UPDATE se_par_expedzone tf SET enreg_id=(select enreg_id FROM &erp.par_expedzone f WHERE f.expedzone_cod=tf.expedzone_cod) ;
 UPDATE se_par_expedzone tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('expedzone_cod','PAR_EXPEDZONE','O') ;

 commit;
 
 
select * from (
SELECT &outils.stragg(source) source,expedzone_cod, enreg_id, enreg_s, expedzone_lib, expedzone_lib2, eloignement_num
FROM (
  SELECT 'uv' source ,g.* FROM se_par_expedzone g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_expedzone g
  )
GROUP BY expedzone_cod, enreg_id, enreg_s, expedzone_lib, expedzone_lib2, eloignement_num
HAVING Count(1)!=2) r
ORDER BY expedzone_cod;